package cn.shafish.nettycommon.codec;

import cn.shafish.nettycommon.dispatcher.Message;
import cn.shafish.nettycommon.util.JacksonUtils;
import com.alibaba.fastjson.JSON;

import java.io.IOException;

/**
 * 指定通信格式
 */
public class Invocation {
    /**
     * 指定消息类型
     */
    private String type;

    /**
     *
     */
    private String message;

    public Invocation() {}

    public Invocation(String type,String message) {
        this.type = type;
        this.message = message;
    }

    public Invocation(String type, Message message) throws IOException {
        this.type = type;
        this.message = JSON.toJSONString(message);//JacksonUtils.toJson(message);
    }

    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    @Override
    public String toString() {
        return "Invocation{" +
                "type='" + type + '\'' +
                ", message='" + message + '\'' +
                '}';
    }
}
